let express = require('express');
let app = express()
let path = require('path')
let cors = require('cors')

app.use(cors())
app.use(express.static(path.join(__dirname, 'public')));
let captcha = [
    { id: 1, imgurl: 'http://127.0.0.1:8080/images/captcha01.jpg', rotate: 90 },
    { id: 2, imgurl: 'http://127.0.0.1:8080/images/captcha02.png', rotate: 180 },
    { id: 3, imgurl: 'http://127.0.0.1:8080/images/captcha03.png', rotate: 270 }
]
let id = 0
app.get('/captcha', function (req, res, next) {
    if (id <= 2) {
        id = id + 1
    } else {
        id = 0
    }
    if (id === 3) {
        id = 0
    }

    let succData = {
        code: 200,
        data: captcha[id]
    }
    res.status(200).send(succData);
});
app.listen(8080, () => {
    console.log("服务器启动完成：", "http://127.0.0.1:8080")
})